import {View, Button, Text} from '@tarojs/components';
import Taro, {getCurrentInstance} from '@tarojs/taro';
import React, {Component} from 'react';

import {connect} from 'react-redux';
import './index.less';
import * as T from './types';
import actions from './actions';
import {store2Props} from './selectors';

import List from './components/list';
import AppointModal from './components/appoint-modal';
import WeChat from './components/weChat';

@connect<Partial<T.IProps>, any>(store2Props, actions)
export default class CommonChoseService extends Component<Partial<T.IProps>, any> {
  constructor(props) {
    super(props);
    this.state = {
      showMessageCard: null,
    };
  }
  componentDidMount() {
    let params = getCurrentInstance().router.params;
    let storeId = params && params.storeId;
    const {showMessageCard, xSite, enterpriseId, serviceUrl} = params;
    this.setState({showMessageCard, xSite, enterpriseId, serviceUrl})
    this.props.actions.init(storeId);
  }

  componentWillUnmount() {
    this.props.actions.clean();
  }

  render() {
    let {
      actions: {action},
      main,
    } = this.props;

    const {showMessageCard, xSite, enterpriseId, serviceUrl} = this.state;
    return main ? (
      <View className="service-main">
          {xSite ? (
              <WeChat enterpriseId={enterpriseId} serviceUrl={serviceUrl} />
            ) : (
              <List showMessageCard={showMessageCard} />
            )}
        {main.isAppointFlag && <AppointModal />}
      </View>
    ) : (
      <View />
    );
  }
}

//create by moon https://github.com/creasy2010/moon
